package com.work.dao.impl;

import com.work.bean.HwStu;
import com.work.dao.BaseDao;
import com.work.dao.HwStuDao;

import java.util.List;

public class HwStuDaoImpl extends BaseDao implements HwStuDao {
    public List<HwStu> queryHwstu() {
        String sql = "SELECT * FROM t_hw_stu  ";
        return  queryForList(HwStu.class,sql);
    }


    public List<HwStu> queryHwstuByHwId(Integer hwId) {
        String sql = "SELECT * FROM t_hw_stu WHERE hw_id = ? ";
        return  queryForList(HwStu.class,sql,hwId);
    }

    public HwStu queryHwstuById(Integer id) {
        String sql = "SELECT * FROM t_hw_stu WHERE id = ? ";
        return  queryForOne(HwStu.class,sql,id);
    }


    public HwStu queryHwstuByTime() {
        String sql = "SELECT * FROM t_hw_stu ORDER BY id DESC LIMIT 1 ";
        return  queryForOne(HwStu.class,sql);
    }

    public int saveHwStu(HwStu hwStu) {
        String sql = "INSERT INTO `t_hw_stu` (`hw_id`, `sid`, `status`) VALUES (?, ?, ?)";
        return update(sql,hwStu.getHw_id(),hwStu.getsId(),hwStu.getStatus());
    }

    public int updateHwStu(HwStu hwStu) {
        String sql = "UPDATE t_hw_stu SET `hw_id `=?,`sid`=?,`status`=? WHERE `id` = ?";
        return update(sql,hwStu.getHw_id(),hwStu.getsId(),hwStu.getStatus(),hwStu.getId());
    }

    @Override
    public int update(HwStu hwStu) {
        String sql = "UPDATE t_hw_stu SET `status`=? WHERE `id` = ?";
        return update(sql,hwStu.getStatus(),hwStu.getId());
    }

    public int deleteHwstu(Integer id) {
        String sql = "DELETE FROM `t_hw_stu` WHERE `id` = ?";
        return update(sql, id);
    }
}
